package com.wyt.cloud.utils.query.strategy;

import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.wyt.cloud.utils.query.anno.FilterParam;

import java.lang.reflect.Field;

public abstract class AbstractMatchStrategy {

    /**
     * 对于字段名而言  queryParam.matchField()手动设置优先级高于当前字段本身名称的优先级
     *
     * @param field
     * @return
     */
    protected String getFieldName(Field field) {
        FilterParam filterParam = field.getAnnotation(FilterParam.class);
        if (filterParam == null) {
            return field.getName();
        }
        String matchField = filterParam.matchField();
        return StringUtils.isNotBlank(matchField) ? matchField : field.getName();
    }

}
